/**
 * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 *
 * This file is a part of the CANN Open Software.
 * Licensed under CANN Open Software License Agreement Version 1.0 (the "License").
 * Please refer to the License for details. You may not use this file except in compliance with the License.
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
 * See LICENSE in the root of the software repository for the full text of the License.
 */
#ifndef ATVC_REDUCE_TILING_DEF_H
#define ATVC_REDUCE_TILING_DEF_H
#include <map>
#include <vector>
#include "graph/types.h"

namespace ATVC {
template <typename T>
inline ge::DataType GetOriInputType() {
    if constexpr (std::is_same<T, float>::value) {
        return ge::DataType::DT_FLOAT;
    } else if constexpr (std::is_same<T, int8_t>::value) {
        return ge::DataType::DT_INT8;
    } else if constexpr (std::is_same<T, int16_t>::value) {
        return ge::DataType::DT_INT16;
    } else if constexpr (std::is_same<T, int32_t>::value) {
        return ge::DataType::DT_INT32;
    } else if constexpr (std::is_same<T, int64_t>::value) {
        return ge::DataType::DT_INT64;
    } else if constexpr (std::is_same<T, uint8_t>::value) {
        return ge::DataType::DT_UINT8;
    }
};

inline ge::DataType GetPromoteDataType(ge::DataType dtype) {
    switch(dtype) {
        case ge::DataType::DT_BF16:
        case ge::DataType::DT_FLOAT16:
        case ge::DataType::DT_FLOAT:
            return ge::DataType::DT_FLOAT;
        case ge::DataType::DT_INT8:
            return ge::DataType::DT_INT8;
        case ge::DataType::DT_INT16:
            return ge::DataType::DT_INT16;
        case ge::DataType::DT_INT32:
            return ge::DataType::DT_INT32;
        case ge::DataType::DT_INT64:
            return ge::DataType::DT_INT64;
    }
    return ge::DataType::DT_UNDEFINED;
}

struct ReduceTilingUnit {
    int32_t idx = -1;    // ub cut axis
    uint64_t inner = 1;  // inner size in ub
    uint64_t outer = 1;  // outer size of ub
    uint64_t step = 1;   // step of cacheline
    void Update(int32_t idx, uint64_t inner, uint64_t outer, uint64_t step)
    {
        this->idx = idx;
        this->inner = inner;
        this->outer = outer;
        this->step = step;
    }
};

struct CacheLineBlock {
    int32_t axis = -1;            // cacheline cut axis
    uint64_t size = 1;            // cacheline size
    uint64_t cacheLineStep = 1;   // cacheline cut size for axis
    uint64_t cacheLineOuter = 1;  // relative to cacheLineStep, out size of cacheline cut axis
    uint64_t aSize = 1;           // A axis size in cacheline
};

struct ReduceTilingInputParam {
    std::vector<int64_t> reduceDim = {};
    std::vector<int64_t> reduceShape = {};
    ge::DataType inputDtype = ge::DataType::DT_UNDEFINED;
    ge::DataType promoteDtpye = ge::DataType::DT_UNDEFINED;
};
};

#endif // ATVC_REDUCE_TILING_COMMON_H